package dao;

import hbt.HibernateUtil;
import negocio.Carta;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class CartaDAO {
	private static CartaDAO instancia = null;
	private static SessionFactory sf = null;
	
	public CartaDAO()
	{
		
	}
	public static CartaDAO getInstancia()
	{
		if (instancia== null)
		{			
			sf = HibernateUtil.getSessionFactory();
			instancia = new CartaDAO();
		}
		return instancia;
	}

	public void grabarCarta(Carta c)
	{
		Session s = sf.openSession();
		s.beginTransaction();
		s.persist(c);
		s.flush();
		s.getTransaction().commit();
		s.close();
	}

	public Carta buscarCarta(int nroCarta) {
		Session session = sf.openSession();
		Carta c = new Carta();
		c.setNroCarta(nroCarta);
		session.load(c, c.getNroCarta());			
		session.close();
		return c;
	}
	
}

